<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>SocketRequest的演示</title>
</head>
<body>
<script>
    // 定义SOCKET_URL，在socketRequest.js中有用到
    const SOCKET_URL = "ws://127.0.0.1:8080/api"
</script>
<!-- 引入封装的socketRequest.js -->
<script src="./js/socketRequest.js"></script>
<script>
    let form = {
        "booleanValue": false,
        "doubleValue": 3.1415926,
        "floatValue": 0.618,
        "intArr": [1, 3, 5, 7, 9],
        "intList": [2, 4, 6, 8, 10],
        "intValue": 18,
        "item": {"age": 18, "id": "abcdefg"},
        "itemList": [{"age": 18, "id": "abcdefg"}, {"age": 18, "id": "abcdefg"}],
        "map": {
            "a": "你好1",
            "b": "世界1",
            "c": {
                "id": 188,
                "name": "小胡",
                "friend": [{"name": "小红", "gender": false, "id": 158}, {
                    "name": "小蓝",
                    "gender": true,
                    "id": 179,
                    "hello": "world"
                }, "无规则"]
            }
        },
        "mapList": [{"a": "你好", "b": "世界", "c": "很大"}, {
            "a": "你好1",
            "b": "世界1",
            "c": {
                "id": 188,
                "name": "小胡",
                "friend": [{"name": "小红", "gender": false, "id": 158}, {
                    "name": "小蓝",
                    "gender": true,
                    "id": 179,
                    "hello": "world"
                }, "无规则"]
            }
        }],
        "passWord": "123456789",
        "shortValue": 32767,
        "strArr": ["123"],
        "strList": [""],
        "userName": "123"
    }
    //需要等待socket连接，所以这里延迟1秒发送请求
    setTimeout(() => {
        console.log("发送的表单数据",form)

        $sget("/user/login", form).then(res => {
            console.log("$sget请求的响应体", res.data)

            console.log("$sget响应.data===form",JSON.stringify(res.data.data)===JSON.stringify(form))
        }).catch(e => {
            console.error("请求失败", e)
        })


        $spost("/user/login", form).then(res => {
            console.log("$spost请求的响应体", res.data)

            console.log("$spost响应.data===form",JSON.stringify(res.data.data)===JSON.stringify(form))
        }).catch(e => {
            console.error("请求失败", e)
        })

    }, 1000)
</script>
</body>
</html>